package com.woniuxy.user.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.commons.request.ResPage;
import com.woniuxy.user.dto.DepartmentDto;
import com.woniuxy.user.entity.Department;
import com.woniuxy.user.mapper.DepartmentMapper;
import com.woniuxy.user.service.DepartmentService;
import com.woniuxy.user.vo.DepartmentVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DepartmentServiceImpl implements DepartmentService {
    @Resource
    private DepartmentMapper departmentMapper;
    @Override
    public ResPage<Department> getDepartmentList(DepartmentVo departmentVo) {
        PageHelper.startPage(departmentVo.getPage(), departmentVo.getSize());
        List<Department> list = departmentMapper.getDepartmentList(departmentVo);
        PageInfo<Department> pageInfo = new PageInfo<>(list);
        return new ResPage<>(pageInfo);
    }

    @Override
    public Boolean addDepartment(Department department) {
        return departmentMapper.addDepartment(department) > 0;
    }

    @Override
    public Boolean editDepartment(Department department) {
        return departmentMapper.editDepartment(department) > 0;
    }

    @Override
    public Boolean enableDepartment(Integer id) {
        return departmentMapper.enableDepartment(id) > 0;
    }

    @Override
    public Boolean disableDepartment(Integer id) {
        return departmentMapper.disableDepartment(id) > 0;
    }

    @Override
    public Boolean deleteDepartment(Integer id) {
        return departmentMapper.deleteDepartment(id) > 0;
    }

    @Override
    public Boolean checkName(String name) {
        return departmentMapper.checkName(name) == 0;
    }

    @Override
    public List<Department> getAllDepartmentList() {
        return departmentMapper.getAllDepartmentList();
    }

    @Override
    public List<DepartmentDto> getDepartmentListForEmployee() {
        return departmentMapper.getDepartmentListForEmployee();
    }

    @Override
    public int increaseDepartmentNum(Integer id) {
        return departmentMapper.increaseDepartmentNum(id);
    }

    @Override
    public int decreaseDepartmentNum(Integer id) {
        return departmentMapper.decreaseDepartmentNum(id);
    }
}
